<?xml version='1.0' encoding='iso-8859-1'?>
<!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
	<head>
		<title>
			ampwait.c
			</title>
		<meta http-equiv='content-type' content='text/html;iso-8859-1'/>
		<meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
		<meta name='author' content='cmaier@cmassoc.net'/>
		<meta name='robots' content='noindex,nofollow'/>
		<link href='toolkit.css' rel='stylesheet' type='text/css'/>
		</head>
	<body>
		<div class='headerlink'>
			[<a href='amptool.c.html' title=' amptool.c '>PREV</a>]
			[<a href='toolkit.html' title=' Index '>HOME</a>]
			[<a href='Antiphon.c.html' title=' Antiphon.c '>NEXT</a>]
			</div>
<pre>
/*====================================================================*
 *
 *   Copyright (c) 2013 Qualcomm Atheros, Inc.
 *
 *   All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or 
 *   without modification, are permitted (subject to the limitations 
 *   in the disclaimer below) provided that the following conditions 
 *   are met:
 *
 *   * Redistributions of source code must retain the above copyright 
 *     notice, this list of conditions and the following disclaimer.
 *
 *   * Redistributions in binary form must reproduce the above 
 *     copyright notice, this list of conditions and the following 
 *     disclaimer in the documentation and/or other materials 
 *     provided with the distribution.
 *
 *   * Neither the name of Qualcomm Atheros nor the names of 
 *     its contributors may be used to endorse or promote products 
 *     derived from this software without specific prior written 
 *     permission.
 *
 *   NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE 
 *   GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE 
 *   COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR 
 *   IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
 *   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
 *   PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 
 *   OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 *   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
 *   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 *   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 *   OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
 *   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 *
 *--------------------------------------------------------------------*/

/*====================================================================*&quot;
 *
 *   ampwait.c -
 *
 *
 *   Contributor(s):
 *      Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
 *      Nathaniel Houghton &lt;nhoughto@qca.qualcomm.com&gt;
 *
 *--------------------------------------------------------------------*/

/*====================================================================*&quot;
 *   system header files;
 *--------------------------------------------------------------------*/

#include &lt;unistd.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdint.h&gt;
#include &lt;limits.h&gt;
#include &lt;sys/time.h&gt;

/*====================================================================*
 *   custom header files;
 *--------------------------------------------------------------------*/

#include &quot;../tools/getoptv.h&quot;
#include &quot;../tools/putoptv.h&quot;
#include &quot;../tools/memory.h&quot;
#include &quot;../tools/number.h&quot;
#include &quot;../tools/symbol.h&quot;
#include &quot;../tools/types.h&quot;
#include &quot;../tools/flags.h&quot;
#include &quot;../tools/files.h&quot;
#include &quot;../tools/timer.h&quot;
#include &quot;../tools/error.h&quot;
#include &quot;../plc/plc.h&quot;

/*====================================================================*
 *   custom source files;
 *--------------------------------------------------------------------*/

#ifndef MAKEFILE
#include &quot;../tools/getoptv.c&quot;
#include &quot;../tools/putoptv.c&quot;
#include &quot;../tools/version.c&quot;
#include &quot;../tools/uintspec.c&quot;
#include &quot;../tools/hexdump.c&quot;
#include &quot;../tools/hexencode.c&quot;
#include &quot;../tools/hexdecode.c&quot;
#include &quot;../tools/todigit.c&quot;
#include &quot;../tools/checkfilename.c&quot;
#include &quot;../tools/synonym.c&quot;
#include &quot;../tools/error.c&quot;
#endif

#ifndef MAKEFILE
#include &quot;../plc/Confirm.c&quot;
#include &quot;../plc/Display.c&quot;
#include &quot;../plc/Failure.c&quot;
#include &quot;../plc/ReadMME.c&quot;
#include &quot;../plc/Request.c&quot;
#include &quot;../plc/SendMME.c&quot;
#include &quot;../plc/Devices.c&quot;
#endif

#ifndef MAKEFILE
#include &quot;../ether/openchannel.c&quot;
#include &quot;../ether/closechannel.c&quot;
#include &quot;../ether/readpacket.c&quot;
#include &quot;../ether/sendpacket.c&quot;
#include &quot;../ether/channel.c&quot;
#endif

#ifndef MAKEFILE
#include &quot;../mme/MMECode.c&quot;
#include &quot;../mme/EthernetHeader.c&quot;
#include &quot;../mme/QualcommHeader.c&quot;
#include &quot;../mme/QualcommHeader1.c&quot;
#include &quot;../mme/UnwantedMessage.c&quot;
#endif

/*====================================================================*
 *
 *   signed ResetAndWait (struct plc * plc);
 *
 *   plc.h
 *
 *   send VS_RS_DEV.REQ messages every channel-&gt;timeout milliseconds
 *   until the device responds to indicate that it is ready to reset;
 *   return 0 if the device eventually responds within plc-&gt;timer
 *   seconds or -1 if not;
 *
 *--------------------------------------------------------------------*/

signed ResetAndWait (struct plc * plc)

{
	struct channel * channel = (struct channel *)(plc-&gt;channel);
	struct message * message = (struct message *)(plc-&gt;message);
	struct timeval ts;
	struct timeval tc;
	unsigned timer = 0;

#ifndef __GNUC__
#pragma pack (push,1)
#endif

	struct __packed vs_rs_dev_request
	{
		struct ethernet_hdr ethernet;
		struct qualcomm_hdr qualcomm;
	}
	* request = (struct vs_rs_dev_request *) (message);
	struct __packed vs_rs_dev_confirm
	{
		struct ethernet_hdr ethernet;
		struct qualcomm_hdr qualcomm;
		uint8_t MSTATUS;
	}
	* confirm = (struct vs_rs_dev_confirm *) (message);

#ifndef __GNUC__
#pragma pack (pop)
#endif

	Request (plc, &quot;Reset when Ready&quot;);
	if (gettimeofday (&amp;ts, NULL) == -1)
	{
		error (1, errno, CANT_START_TIMER);
	}
	for (timer = 0; timer &lt; plc-&gt;timer; timer = SECONDS (ts, tc))
	{
		memset (message, 0, sizeof (* message));
		EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
		QualcommHeader (&amp;request-&gt;qualcomm, 0, (VS_RS_DEV | MMTYPE_REQ));
		plc-&gt;packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
		if (SendMME (plc) &lt;= 0)
		{
			error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
			return (-1);
		}
		if (ReadMME (plc, 0, (VS_RS_DEV | MMTYPE_CNF)) &lt; 0)
		{
			error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
			return (-1);
		}
		if (gettimeofday (&amp;tc, NULL) == -1)
		{
			error (1, errno, CANT_RESET_TIMER);
		}
		if (plc-&gt;packetsize)
		{
			if (!confirm-&gt;MSTATUS)
			{
				Confirm (plc, &quot;Resetting ...&quot;);
				return (0);
			}
		}
	}
	return (-1);
}

/*====================================================================*
 *
 *   signed WaitForReset (struct plc * plc, char string [], size_t length);
 *
 *   plc.h
 *
 *   send VS_SW_VER.REQ  messages every channel-&gt;timeout milliseconds
 *   until the device stops responding to indicate that it is inactive;
 *   return 0 if the device eventually stops responding within
 *   plc-&gt;timer seconds or -1 if not;
 *
 *   this function cannot distinguish between a software reset and
 *   hardware reset;
 *
 *--------------------------------------------------------------------*/

signed WaitForReset (struct plc * plc, char string [], size_t length)

{
	struct channel * channel = (struct channel *)(plc-&gt;channel);
	struct message * message = (struct message *)(plc-&gt;message);
	struct timeval ts;
	struct timeval tc;
	unsigned timer = 0;

#ifndef __GNUC__
#pragma pack (push,1)
#endif

	struct __packed vs_sw_ver_request
	{
		struct ethernet_hdr ethernet;
		struct qualcomm_hdr qualcomm;
		uint8_t MSTATUS;
		uint8_t MDEVICEID;
		uint8_t MVERLENGTH;
		char MVERSION [PLC_VERSION_STRING];
	}
	* request = (struct vs_sw_ver_request *) (message);
	struct __packed vs_sw_ver_confirm
	{
		struct ethernet_hdr ethernet;
		struct qualcomm_hdr qualcomm;
		uint8_t MSTATUS;
		uint8_t MDEVICEID;
		uint8_t MVERLENGTH;
		char MVERSION [PLC_VERSION_STRING];
	}
	* confirm = (struct vs_sw_ver_confirm *) (message);

#ifndef __GNUC__
#pragma pack (pop)
#endif

	memset (string, 0, length);
	Request (plc, &quot;Allow %d seconds for Reset&quot;, plc-&gt;timer);
	if (gettimeofday (&amp;ts, NULL) == -1)
	{
		error (1, errno, CANT_START_TIMER);
	}
	for (timer = 0; timer &lt; plc-&gt;timer; timer = SECONDS (ts, tc))
	{
		memset (message, 0, sizeof (* message));
		EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
		QualcommHeader (&amp;request-&gt;qualcomm, 0, (VS_SW_VER | MMTYPE_REQ));
		plc-&gt;packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
		if (SendMME (plc) &lt;= 0)
		{
			error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
			return (-1);
		}
		if (ReadMME (plc, 0, (VS_SW_VER | MMTYPE_CNF)) &lt; 0)
		{
			error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
			return (-1);
		}
		if (gettimeofday (&amp;tc, NULL) == -1)
		{
			error (1, errno, CANT_RESET_TIMER);
		}
		if (!plc-&gt;packetsize)
		{
			if (_allset (plc-&gt;flags, (PLC_WAITFORRESET | PLC_ANALYSE)))
			{
				Confirm (plc, &quot;Waited %d seconds for Reset&quot;, timer);
			}
			memcpy (string, confirm-&gt;MVERSION, confirm-&gt;MVERLENGTH);
			return (0);
		}
	}
	if (_allset (plc-&gt;flags, (PLC_WAITFORRESET | PLC_ANALYSE)))
	{
		Confirm (plc, &quot;Waited %d seconds for Reset&quot;, timer);
	}
	return (-1);
}

/*====================================================================*
 *
 *   signed WaitForStart (struct plc * plc, char string [], size_t length);
 *
 *   plc.h
 *
 *   send VS_SW_VER.REQ messages every channel-&gt;timeout milliseconds
 *   until the device responds to indicate that it is active; return
 *   0 if the device eventually responds within plc-&gt;timer seconds
 *   or -1 if not;
 *
 *--------------------------------------------------------------------*/

signed WaitForStart (struct plc * plc, char string [], size_t length)

{
	struct channel * channel = (struct channel *)(plc-&gt;channel);
	struct message * message = (struct message *)(plc-&gt;message);
	struct timeval ts;
	struct timeval tc;
	unsigned timer = 0;

#ifndef __GNUC__
#pragma pack (push,1)
#endif

	struct __packed vs_sw_ver_request
	{
		struct ethernet_hdr ethernet;
		struct qualcomm_hdr qualcomm;
		uint8_t MSTATUS;
		uint8_t MDEVICEID;
		uint8_t MVERLENGTH;
		char MVERSION [PLC_VERSION_STRING];
	}
	* request = (struct vs_sw_ver_request *) (message);
	struct __packed vs_sw_ver_confirm
	{
		struct ethernet_hdr ethernet;
		struct qualcomm_hdr qualcomm;
		uint8_t MSTATUS;
		uint8_t MDEVICEID;
		uint8_t MVERLENGTH;
		char MVERSION [PLC_VERSION_STRING];
	}
	* confirm = (struct vs_sw_ver_confirm *) (message);

#ifndef __GNUC__
#pragma pack (pop)
#endif

	Request (plc, &quot;Allow %d seconds for Start&quot;, plc-&gt;timer);
	if (gettimeofday (&amp;ts, NULL) == -1)
	{
		error (1, errno, CANT_START_TIMER);
	}
	for (timer = 0; timer &lt; plc-&gt;timer; timer = SECONDS (ts, tc))
	{
		memset (message, 0, sizeof (* message));
		EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
		QualcommHeader (&amp;request-&gt;qualcomm, 0, (VS_SW_VER | MMTYPE_REQ));
		plc-&gt;packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
		if (SendMME (plc) &lt;= 0)
		{
			error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
			return (-1);
		}
		if (ReadMME (plc, 0, (VS_SW_VER | MMTYPE_CNF)) &lt; 0)
		{
			error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
			return (-1);
		}
		if (gettimeofday (&amp;tc, NULL) == -1)
		{
			error (1, errno, CANT_RESET_TIMER);
		}
		if (plc-&gt;packetsize)
		{
			if (confirm-&gt;MSTATUS)
			{
				Failure (plc, PLC_WONTDOIT);
				return (-1);
			}
			if (_allset (plc-&gt;flags, (PLC_WAITFORSTART | PLC_ANALYSE)))
			{
				Confirm (plc, &quot;Waited %d seconds for Start&quot;, timer);
			}
			strncpy (string, confirm-&gt;MVERSION, length);
			return (0);
		}
	}
	if (_allset (plc-&gt;flags, (PLC_WAITFORSTART | PLC_ANALYSE)))
	{
		Confirm (plc, &quot;Waited %d seconds for Start&quot;, timer);
	}
	return (-1);
}

/*====================================================================*
 *
 *   signed WaitForAssoc (struct plc * plc);
 *
 *   plc.h
 *
 *   send VS_NW_INFO.REQ messages every channel-&gt;timeout milliseconds
 *   until the device reports that a network has formed; return 0 if a
 *   network forms within plc-&gt;timer seconds or -1 if not;
 *
 *--------------------------------------------------------------------*/

signed WaitForAssoc (struct plc * plc)

{
	extern const uint8_t broadcast [ETHER_ADDR_LEN];
	struct channel * channel = (struct channel *)(plc-&gt;channel);
	struct message * message = (struct message *)(plc-&gt;message);
	struct timeval ts;
	struct timeval tc;
	unsigned timer = 0;

#ifndef __GNUC__
#pragma pack (push,1)
#endif

	struct __packed vs_nw_info_request
	{
		struct ethernet_hdr ethernet;
		struct qualcomm_fmi qualcomm;
	}
	* request = (struct vs_nw_info_request *)(message);
	struct __packed vs_nw_info_confirm
	{
		struct ethernet_hdr ethernet;
		struct qualcomm_fmi qualcomm;
		uint8_t SUB_VERSION;
		uint8_t Reserved;
		uint16_t DATA_LEN;
		uint8_t DATA [1];
	}
	* confirm = (struct vs_nw_info_confirm *)(message);
	struct __packed station
	{
		uint8_t MAC [ETHER_ADDR_LEN];
		uint8_t TEI;
		uint8_t Reserved [3];
		uint8_t BDA [ETHER_ADDR_LEN];
		uint16_t AVGTX;
		uint8_t COUPLING;
		uint8_t Reserved3;
		uint16_t AVGRX;
		uint16_t Reserved4;
	}
	* station;
	struct __packed network
	{
		uint8_t NID [7];
		uint8_t Reserved1 [2];
		uint8_t SNID;
		uint8_t TEI;
		uint8_t Reserved2 [4];
		uint8_t ROLE;
		uint8_t CCO_MAC [ETHER_ADDR_LEN];
		uint8_t CCO_TEI;
		uint8_t Reserved3 [3];
		uint8_t NUMSTAS;
		uint8_t Reserved4 [5];
		struct station stations [1];
	}
	* network;
	struct __packed networks
	{
		uint8_t Reserved;
		uint8_t NUMAVLNS;
		struct network networks [1];
	}
	* networks = (struct networks *) (confirm-&gt;DATA);

#ifndef __GNUC__
#pragma pack (pop)
#endif

	Request (plc, &quot;Allow %d seconds for Assoc&quot;, plc-&gt;timer);
	if (gettimeofday (&amp;ts, NULL) == -1)
	{
		error (1, errno, CANT_START_TIMER);
	}
	for (timer = 0; timer &lt; plc-&gt;timer; timer = SECONDS (ts, tc))
	{
		memset (message, 0, sizeof (* message));
		EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
		QualcommHeader1 (&amp;request-&gt;qualcomm, 1, (VS_NW_INFO | MMTYPE_REQ));
		plc-&gt;packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
		if (SendMME (plc) &lt;= 0)
		{
			error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
			return (-1);
		}
		if (ReadMME (plc, 1, (VS_NW_INFO | MMTYPE_CNF)) &lt; 0)
		{
			error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
			return (-1);
		}
		if (gettimeofday (&amp;tc, NULL) == -1)
		{
			error (1, errno, CANT_RESET_TIMER);
		}
		if (plc-&gt;packetsize)
		{
			network = (struct network *)(&amp;networks-&gt;networks);
			while (networks-&gt;NUMAVLNS--)
			{
				station = (struct station *)(&amp;network-&gt;stations);
				while (network-&gt;NUMSTAS--)
				{
					if (memcmp (station-&gt;MAC, broadcast, sizeof (broadcast)))
					{
						if (_allset (plc-&gt;flags, (PLC_WAITFORASSOC | PLC_ANALYSE)))
						{
							Confirm (plc, &quot;Waited %d seconds for Assoc&quot;, timer);
						}
						return (0);
					}
					station++;
				}
				network = (struct network *)(station);
			}
		}
	}
	if (_allset (plc-&gt;flags, (PLC_WAITFORASSOC | PLC_ANALYSE)))
	{
		Confirm (plc, &quot;Waited %d seconds for Assoc&quot;, timer);
	}
	return (-1);
}

/*====================================================================*
 *
 *   void function (struct plc * plc, char const * firmware);
 *
 *   perform operations in a logical order;
 *
 *
 *--------------------------------------------------------------------*/

static void function (struct plc * plc, char const * firmware)

{
	char string [PLC_VERSION_STRING];
	if (_anyset (plc-&gt;flags, PLC_RESET_DEVICE))
	{
		if (ResetAndWait (plc))
		{
			Failure (plc, &quot;Device did not Reset.&quot;);
		}
	}
	if (_anyset (plc-&gt;flags, PLC_WAITFORRESET))
	{
		if (WaitForReset (plc, string, sizeof (string)))
		{
			Failure (plc, &quot;Device did not Reset.&quot;);
		}
	}
	if (_anyset (plc-&gt;flags, PLC_WAITFORSTART))
	{
		if (WaitForStart (plc, string, sizeof (string)))
		{
			Failure (plc, &quot;Device did not Start.&quot;);
		}
		if ((firmware) &amp;&amp; (*firmware) &amp;&amp; strcmp (firmware, string))
		{
			Failure (plc, &quot;Started wrong firmware&quot;);
		}
	}
	if (_anyset (plc-&gt;flags, PLC_WAITFORASSOC))
	{
		if (WaitForAssoc (plc))
		{
			Failure (plc, &quot;Device did not Assoc.&quot;);
		}
	}
	if (plc-&gt;sleep)
	{
		Request (plc, &quot;Pause %d seconds&quot;, plc-&gt;sleep);
		sleep (plc-&gt;sleep);
	}
	return;
}

/*====================================================================*
 *
 *   int main (int argc, char const * argv[]);
 *
 *   parse command line, populate plc structure and perform selected
 *   operations; show help summary if asked; see getoptv and putoptv
 *   to understand command line parsing and help summary display; see
 *   plc.h for the definition of struct plc;
 *
 *   the command line accepts multiple MAC addresses and the program
 *   performs the specified operations on each address, in turn; the
 *   address order is significant but the option order is not; the
 *   default address is a local broadcast that causes all devices on
 *   the local H1 interface to respond but not those at the remote
 *   end of the powerline;
 *
 *   the default address is 00:B0:52:00:00:01; omitting the address
 *   will automatically address the local device; some options will
 *   cancel themselves if this makes no sense;
 *
 *   the default interface is eth1 because most people use eth0 as
 *   their principle network connection; you can specify another
 *   interface with -i or define environment string PLC to make
 *   that the default interface and save typing;
 *
 *
 *--------------------------------------------------------------------*/

int main (int argc, char const * argv [])

{
	extern struct channel channel;
	static char const * optv [] =
	{
		&quot;aef:i:p:qrRstvw:xy&quot;,
		&quot;device [device] [...] [&gt; stdout]&quot;,
		&quot;Qualcomm Atheros Powerline Procrastinator&quot;,
		&quot;a\twait for device assoc&quot;,
		&quot;e\tredirect stderr to stdout&quot;,
		&quot;f s\tconfirm firmware is revision s&quot;,

#if defined (WINPCAP) || defined (LIBPCAP)

		&quot;i n\thost interface is (n) [&quot; LITERAL (CHANNEL_ETHNUMBER) &quot;]&quot;,

#else

		&quot;i s\thost interface is (s) [&quot; LITERAL (CHANNEL_ETHDEVICE) &quot;]&quot;,

#endif

		&quot;p n\tpause (n) seconds&quot;,
		&quot;q\tquiet mode&quot;,
		&quot;r\twait for device reset&quot;,
		&quot;R\treset device and wait&quot;,
		&quot;s\twait for device start&quot;,
		&quot;t n\tchannel timeout is (n) milliseconds [&quot; LITERAL (CHANNEL_TIMEOUT) &quot;]&quot;,
		&quot;v\tverbose mode&quot;,
		&quot;w n\twait up to (n) seconds for action [&quot; LITERAL (PLC_TIMER) &quot;]&quot;,
		&quot;x\texit on error&quot;,
		&quot;y\treport failure times&quot;,
		(char const *) (0)
	};

#include &quot;../plc/plc.c&quot;

	char const * firmware = &quot;&quot;;
	signed c;
	if (getenv (PLCDEVICE))
	{

#if defined (WINPCAP) || defined (LIBPCAP)

		channel.ifindex = atoi (getenv (PLCDEVICE));

#else

		channel.ifname = strdup (getenv (PLCDEVICE));

#endif

	}
	optind = 1;
	while ((c = getoptv (argc, argv, optv)) != -1)
	{
		switch (c)
		{
		case 'a':
			_setbits (plc.flags, PLC_WAITFORASSOC);
			break;
		case 'e':
			dup2 (STDOUT_FILENO, STDERR_FILENO);
			break;
		case 'f':
			firmware = optarg;
			break;
		case 'i':

#if defined (WINPCAP) || defined (LIBPCAP)

			channel.ifindex = atoi (optarg);

#else

			channel.ifname = optarg;

#endif

			break;
		case 'p':
			plc.sleep = (unsigned)(uintspec (optarg, 0, 3600));
			break;
		case 'q':
			_setbits (channel.flags, CHANNEL_SILENCE);
			_setbits (plc.flags, PLC_SILENCE);
			break;
		case 'r':
			_setbits (plc.flags, PLC_WAITFORRESET);
			break;
		case 'R':
			_setbits (plc.flags, PLC_RESET_DEVICE);
			break;
		case 's':
			_setbits (plc.flags, PLC_WAITFORSTART);
			break;
		case 't':
			channel.timeout = (signed)(uintspec (optarg, 0, UINT_MAX));
			break;
		case 'v':
			_setbits (channel.flags, CHANNEL_VERBOSE);
			_setbits (plc.flags, PLC_VERBOSE);
			break;
		case 'w':
			plc.timer = (unsigned)(uintspec (optarg, 0, 86400));
			break;
		case 'x':
			_setbits (plc.flags, PLC_BAILOUT);
			break;
		case 'y':
			_setbits (plc.flags, PLC_ANALYSE);
			break;
		default:
			break;
		}
	}
	argc -= optind;
	argv += optind;
	openchannel (&amp;channel);
	if (!(plc.message = malloc (sizeof (* plc.message))))
	{
		error (1, errno, PLC_NOMEMORY);
	}
	if (!argc)
	{
		function (&amp;plc, firmware);
	}
	while ((argc) &amp;&amp; (* argv))
	{
		if (!hexencode (channel.peer, sizeof (channel.peer), synonym (* argv, devices, SIZEOF (devices))))
		{
			error (1, errno, PLC_BAD_MAC, * argv);
		}
		function (&amp;plc, firmware);
		argv++;
		argc--;
	}
	free (plc.message);
	closechannel (&amp;channel);
	exit (0);
}


</pre>
		<div class='footerlink'>
			[<a href='amptool.c.html' title=' amptool.c '>PREV</a>]
			[<a href='toolkit.html' title=' Index '>HOME</a>]
			[<a href='Antiphon.c.html' title=' Antiphon.c '>NEXT</a>]
			</div>
		</body>
	</html>
